package util;

import org.apache.batik.dom.events.DOMMouseEvent;
import org.w3c.dom.Element;
import org.w3c.dom.events.Event;

import svg.BoardAdapter;
import svg.GameController;

public class StarListener extends ObjectListener
{

	public StarListener(GameController controller, BoardAdapter boardAdapter)
	{
		super(controller, boardAdapter);
	}

	@Override
	public void fire(Event evt)
	{
		DOMMouseEvent event = (DOMMouseEvent) evt;
		String eventType = event.getType();
		Element target = (Element) event.getTarget();
		Element parent = (Element) target.getParentNode();
		String parentId = parent.getAttribute(IDs.ID.toString());
		int position = Integer.parseInt(parentId.substring(4));
		
		if (eventType.equals(EventType.MOUSE_OVER.toString()))
		{
			_boardAdapter.setStarShadeColor(PAGColor.RED, position);
		}
		else if (eventType.equals(EventType.MOUSE_OUT.toString()))
		{
			_boardAdapter.setStarShadeColor(PAGColor.BLACK, position);
		}
		else if (eventType.equals(EventType.MOUSE_UP.toString()))
		{
			_boardAdapter.setStarShade(true, position);
		}
		else if (eventType.equals(EventType.MOUSE_DOWN.toString()))
		{
			_boardAdapter.setStarShade(false, position);
		}
		else if (eventType.equals(EventType.CLICK.toString()))
		{
			_controller.clickStar(position);
		}
		else
		{
			 throw new IllegalArgumentException("No valid EventType: " + eventType);
		}
	}

}
